/**
 * 充值管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="margin-t10">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>充值/退款记录</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="boxBlock"> 
      <div class="serachTop"> 
           <!-- 搜索筛选 -->
          <el-form :inline="true" :model="formInline" class="user-search">
            <!-- <el-form-item >
              <el-input
                size="small"
                v-model="formInline.userId"
                placeholder="输入用户ID"
                clearable
              ></el-input>
            </el-form-item> -->
            <el-form-item >
              <el-input
                size="small"
                v-model="formInline.userId"
                placeholder="请输入使用者ID" 
                type="number"
                clearable
              ></el-input>
            </el-form-item> 
            <el-form-item >
              <el-input
                size="small"
                v-model="formInline.parentUserId"
                placeholder="请输入所有者ID"
                type="number"
                clearable
              ></el-input>
            </el-form-item>  
            <el-form-item label="">
              <el-input
                size="small"
                v-model="formInline.cardNo"
                placeholder="输入卡号后四位"
                type="number"

                clearable
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="value1"
                size="small"
                type="datetimerange"
                value-format="timestamp"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="createdData"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-select
                size="small"
                v-model="formInline.type"
                placeholder="请选择操作类型"
                clearable
              >
                <el-option
                  v-for="type in typeData"
                  :label="type.key"
                  :value="type.value"
                  :key="type.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-search"
                @click="search"
              >
                搜索
              </el-button>
            </el-form-item>
          </el-form>
          <el-button size="small" type="primary" icon="el-icon-download" @click="exportEx()">
            导出
          </el-button>
      </div> 
   
    <!--列表-->
    <div class="ra_box"> 
      <el-table
        size="small"
        :data="listData"
        highlight-current-row
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 100%"
        v-if="listData"
      >
        <!-- <el-table-column
          prop="userId"
          label="用户ID"
          show-overflow-tooltip
          width="80"
        >
        </el-table-column> -->
        <el-table-column
             prop="parentUserId"
            label="所有者ID"
            show-overflow-tooltip
            width="120"
          >
          </el-table-column>
          <el-table-column
            prop="userId"
            label="使用者ID"
            show-overflow-tooltip
            width="120"
          >
         </el-table-column>
        <el-table-column prop="cardNo" label="卡号" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="arrivalAmount"
          label="充值/退回金额"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <div>
              {{
                b(
                  scope.row.type == 1
                    ? scope.row.rechargeAmount
                    : scope.row.returnAmount
                )
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="rechargeFee"
          label="手续费"
          show-overflow-tooltip
          width="80"
        >
          <template slot-scope="scope">
            <div>
              {{
                b(
                  scope.row.type == 1
                    ? scope.row.rechargeFee
                    : scope.row.returnFeeAmount
                )
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="arrivalAmount"
          label="到账金额"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <div>
              {{ b(scope.row.arrivalAmount) }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="cardBalance"
          label="卡余额"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <div>{{ b(scope.row.cardBalance) }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="交易类型" show-overflow-tooltip>
          <template slot-scope="scope">
            <div>{{ typeData[scope.row.type].key }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="createdAt"
          label="操作时间"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <div>{{ timestampToTime(scope.row.createdAt) }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="150">
          <template slot-scope="scope">
            <el-button size="mini" plain @click="handleEdit(scope.$index, scope.row)">
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
  </div>
    <!-- 编辑界面 -->
    <el-dialog
      :close-on-click-modal="false"
      title="查看"
      :visible.sync="editFormVisible"
      width="30%"
      @close="closeDialog"
    >
      <el-form label-width="120px" :model="editForm" ref="editForm">
        <el-form-item label="流水号" prop="requestId">
          {{ editForm.requestId ? editForm.requestId : editForm.transactionId }}
        </el-form-item>
        <el-form-item label="卡号" prop="cardNo">
          {{ editForm.cardNo }}
        </el-form-item>
        <el-form-item
          label="充值金额"
          prop="rechargeAmount"
          v-if="editForm.type == 1"
        >
          {{ b(editForm.rechargeAmount) }}
        </el-form-item>
        <el-form-item
          label="退款金额"
          prop="returnAmount "
          v-if="editForm.type == 2"
        >
          {{ b(editForm.returnAmount) }}
        </el-form-item>
        <el-form-item label="手续费" prop="rechargeFee">
          {{
            b(
              editForm.type == 1
                ? editForm.rechargeFee
                : editForm.returnFeeAmount
            )
          }}
        </el-form-item>
        <el-form-item label="到账金额" prop="arrivalAmount">
          {{ b(editForm.arrivalAmount) }}
        </el-form-item>
        <el-form-item label="卡余额" prop="cardBalance">
          {{ b(editForm.cardBalance) }}
        </el-form-item>
        <el-form-item label="交易类型" prop="type" v-if="editForm.type">
          {{ typeData[editForm.type].key }}
        </el-form-item>
        <el-form-item label="操作时间" prop="createdAt">
          {{ timestampToTime(editForm.createdAt) }}
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import {
  setStoreS,
  getStoreS,
  removeStoreS,
  insertCharacter,
  timestampToTime,
  timestampSubTime,
  spStr,
} from "../../utils/util";
import {
  baseURL,
  req,
  service,
  encrypt,
  decrypt,
  reqtoken,
  reqField,
  format,
  getUrl,
} from "../../api/axiosFun";
import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
      loading: false,
      addFormVisible: false,
      editFormVisible: false,
      b: format,
      timestampToTime: timestampToTime,
      title: "添加",
      typeData: [
        { key: "请选择交易类型", value: "" },
        { key: "充值", value: 1 },
        { key: "退款", value: 2 },
      ],
      editForm: {},
      value1: "",
      formInline: {
        pageNum: 1,
        pageSize: 10,
        cardNo: "",
        type: "",
        userId: "",
        createdAtStart: "",
        createdAtEnd: "",
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
      hasPermission:false

    };
  },
  // 注册组件
  components: {
    Pagination,
  },
  created() {
    this.getdata(this.formInline);
  },
  methods: {
    exportEx() {
      let url = getUrl(this.formInline);
      service
        .post("/api/admin/exportCardRecordList" + url, {})
        .then((res) => {
          this.loading = false; 
          if (res.code == 0) {
            window.open(
              baseURL + "/common/download?fileName=" + res.msg,
              "_blank"
            );
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    createdData() {
      if (this.value1) {
        this.formInline.createdAtStart = timestampSubTime(
          this.value1[0]
        );
        this.formInline.createdAtEnd = timestampSubTime(
          this.value1[1]
        );
      } else {
        this.formInline.createdAtStart = "";
        this.formInline.createdAtEnd = "";
      }
    },
    getdata(parameter) {
      let url = getUrl(parameter);
      service
        .get("/api/admin/getCardRecordList" + url, {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.listData = res.rows;
            this.pageparm.currentPage = this.formInline.pageNum;
            this.pageparm.pageSize = this.formInline.pageSize;
            this.pageparm.total = res.total;
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageNum = parm.currentPage;
      this.formInline.pageSize = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    },
    //显示编辑界面
    handleEdit(index, row) {
      this.editFormVisible = true;
      this.title = "修改";
      this.editForm = row;
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
</style>

 
 